<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <button>按钮1</button>
    <button>按钮2</button>
    <button>按钮3</button>
    <button>按钮4</button>
    <button>按钮5</button>

    <script>
            const btnObj = document.querySelectorAll("button")
            for(const btn of btnObj){
                btn.onclick = function(){
                    initialColor(btnObj)
                    this.style.backgroundColor = 'red'
                    
                }
                function initialColor(btn){
                    for(const btn of btnObj){
                        btn.style.backgroundColor = '';
                    }
                }
            }

    </script>
</body>

</html>